/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* C STD */
#include "stdio.h"
#include "string.h"
#include "stdbool.h"


/* HAL */
#include "usart.h"

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define LCD_TEST_Pin GPIO_PIN_13
#define LCD_TEST_GPIO_Port GPIOC
#define CHARG_Pin GPIO_PIN_0
#define CHARG_GPIO_Port GPIOA
#define POWER_ENABLE_Pin GPIO_PIN_1
#define POWER_ENABLE_GPIO_Port GPIOA
#define WAKE_Pin GPIO_PIN_2
#define WAKE_GPIO_Port GPIOA
#define WAKE_EXTI_IRQn EXTI2_IRQn
#define HR_INT_Pin GPIO_PIN_3
#define HR_INT_GPIO_Port GPIOA
#define LCD_RST_Pin GPIO_PIN_6
#define LCD_RST_GPIO_Port GPIOA
#define LCD_CS_Pin GPIO_PIN_0
#define LCD_CS_GPIO_Port GPIOB
#define LCD_DC_Pin GPIO_PIN_1
#define LCD_DC_GPIO_Port GPIOB
#define TP_INT_Pin GPIO_PIN_2
#define TP_INT_GPIO_Port GPIOB
#define TP_RST_Pin GPIO_PIN_10
#define TP_RST_GPIO_Port GPIOB
#define LCD_BL_Pin GPIO_PIN_15
#define LCD_BL_GPIO_Port GPIOA
#define MPU_INT_Pin GPIO_PIN_5
#define MPU_INT_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */

extern volatile uint8_t myFlags;
enum FLAG_BIT{
	FLAG_BIT_hr_running,
	FLAG_BIT_max_mpu_canSchedule,
	FLAG_BIT_cd_running,
	FLAG_BIT_blt_state,
	FLAG_BIT_sw_stop_state,
	FLAG_BIT_time_synced
};

#define GET_FLAG(x)				(myFlags & (1 << x))
#define SET_FLAG(x, v)			if(v){myFlags|=(1 << x);}else{myFlags&=~(1 << x);}
#define TOGGLE_FLAG(x)			SET_FLAG(x, !GET_FLAG(x))


#define POWER_ON		HAL_GPIO_WritePin(POWER_ENABLE_GPIO_Port, POWER_ENABLE_Pin, GPIO_PIN_SET)
#define POWER_OFF		HAL_GPIO_WritePin(POWER_ENABLE_GPIO_Port, POWER_ENABLE_Pin, GPIO_PIN_RESET)


/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
